import {Component} from "react";
import React from "react";
import Do from './Do'
class To extends Component{
    constructor(){
        super();
        this.state={
            userName:'2',
            content:'2'
        };
        this.changeUserName=this.changeUserName.bind(this);
        this.changeContent=this.changeContent.bind(this);
        this.add=this.add.bind(this);
    }
    render(){
        return(
            <div>
                <div>
                    <input type='text' value={this.state.userName} onChange={this.changeUserName}/>
                </div>
                <div>
                    <input type='text' value={this.state.content} onChange={this.changeContent}/>
                </div>
                <Do add={this.add} />
            </div>
        )
    }
    changeUserName(ev){
        this.setState({
            userName:ev.target.value
        })
    }
    changeContent(ev){
        this.setState({
            content:ev.target.value
        })
    }
    add(){
        let json={
            userName:this.state.userName,
            content:this.state.content
        };
        let newArr=this.props.list;
        newArr.push(json);
        this.props.submitData(newArr);
    }

}
export default To;